<?php 
class Customer extends TRecord
{ 
    const ...
    private $skills;

    public function clearParts() 
    { 
        $this->contacts  = array(); 
        $this->skills    = array(); 
    }

    public function addSkill(Skill $skill) 
    { 
        $this->skills[] = $skill; 
    } 
    
    public function getSkills() 
    { 
        return $this->skills; 
    }


    public function load($id) 
    { 
        $criteria = new TCriteria; 
        $criteria->add(new TFilter('customer_id', '=', $id)); 
        
        $customer_skill_rep = new TRepository('CustomerSkill'); 
        $customer_skills = $customer_skill_rep->load($criteria); 
        if ($customer_skills) 
        { 
            foreach ($customer_skills as $customer_skill) 
            { 
                $skill = new Skill($customer_skill-> skill_id); 
                $this->addSkill($skill); 
            } 
        } 
        
        return parent::load($id); 
    }
    
    public function store() 
    { 
        parent::store(); 
        
        $criteria = new TCriteria; 
        $criteria->add(new TFilter('customer_id', '=', $this->id)); 
        
        $customer_skill_rep = new TRepository('CustomerSkill'); 
        $customer_skill_rep->delete($criteria); 
        
        if ($this->skills) 
        { 
            foreach ($this->skills as $skill) 
            { 
                $customer_skill = new CustomerSkill; 
                $customer_skill-> customer_id  = $this-> id; 
                $customer_skill-> skill_id     = $skill-> id; 
                $customer_skill->store(); 
            } 
        } 
    }
    
    public function delete($id = NULL) 
    { 
        $id = isset($id) ? $id : $this->{'id'}; 
        
        $criteria = new TCriteria; 
        $criteria->add(new TFilter('customer_id', '=', $id)); 
        
        $repository = new TRepository('CustomerSkill'); 
        $repository->delete($criteria); 
        
        parent::delete($id); 
    } 
} 
?>